/**
 * @AppTest2.java  COPYRIGHT xiaojian
 * 
 * Created on 2018年11月13日 下午4:38:34
 */
package xj.toolkit.bean.bytebean;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import xj.toolkit.bean.bytebean.core.BeanFieldCodec;
import xj.toolkit.util.ByteUtils;

/**
 * @author <a href="mailto:cxj2000@gmail.com">xiaojian.cao</a>
 *
 */
public class AppTest2 {
	
	public static void main(String[] args) {
		AbstractApplicationContext ctx = new ClassPathXmlApplicationContext(
				"codec.xml");

		BeanFieldCodec beanCodec = (BeanFieldCodec) ctx.getBean("byteBeanCodec");
		
//		ArrayList<StringBeanDemo> lst = Lists.newArrayList();
		
		StringBeanDemo a = new StringBeanDemo();
		a.name = "XUAN";
		a.nameLen = a.name.getBytes().length;
		
		
		System.out.println("宣骏".length());
		System.out.println("宣骏".getBytes().length);
		
//		lst.add(a);
		
		// 00 06 58 55 41 4E 00 00 
		
		byte[] bytesBody = beanCodec.encode(beanCodec
				.getEncContextFactory().createEncContext(a, StringBeanDemo.class,
						null));
		
		System.out.println(ByteUtils.bytesAsHexString(bytesBody, 1024));

		System.out.println(beanCodec.decode(beanCodec
				.getDecContextFactory().createDecContext(bytesBody,
						StringBeanDemo.class, null, null)).getValue());
	
		ctx.close();
	}

}
